/**
 * 浮动圆环
 * @namespace Note.CircleFloatBox
 * @author JunEnstein 2017-05-22
 * @param  {HTMLElement} parent HTML父对象
 * @param  {Array} config_items 子元素的配置信息
 */
Note.CircleFloatBox = function(parent, config_items, position){
	/**
	 * 父对象的HTML元素对象
	 * @type {HTMLElement}
	 */
	this._parent = parent;
	
	/**
	 * 浮动球本身的对象
	 * @type {HTMLElement}
	 */
	this.element = null;

	/**
	 * 初始化HTML元素
	 */
	this._createElements(config_items);
};

/**
 * 创建HTML元素
 * @method _createElements
 * @author JunEnstein 2017-05-22
 * @param  {Array} config_items 子元素的配置信息
 */
Note.CircleFloatBox.prototype._createElements = function(config_items){
	/**
	 * css样式类名
	 * @type {Object}
	 */
	var className = {
		circle: "note-circle",
		open: "note-circle note-open",
		ring : "note-ring",
		item : "note-menuItem fa fa-2x fa-",
		center : "note-center fa fa-th fa-2x"
	};
	
	/**
	 * css悬浮提示信息
	 * @type {Object}
	 */
	var titleinfo = new Array(
		"截取当前屏幕",
		"截取整个网页",
		"退出网页标记",
		"打印当前内容",
		"保存到云端",
		"登录账号"
	);
	
	
	// 创建圆环
	var circle = document.createElement("div");
	circle.className = className["circle"];

	// 创建ring
	var ring = document.createElement("div");
	ring.className = className["ring"];

	// 创建item对象
	for(var i = 0; i < config_items.length; i++){
		var item = document.createElement("a");
		item.href = "javascript:void(0);";
		item.className = className["item"] + config_items[i].icon;
		item.title = titleinfo[i];
		// 计算位置
		var t = -0.5 * Math.PI - (i/config_items.length)*2*Math.PI;
		item.style.left = (50 - 35 * Math.cos(t)).toFixed(4) + "%";
		item.style.top  = (50 + 35 * Math.sin(t)).toFixed(4) + "%";
		// 添加回调函数
		if(config_items[i].callback != undefined)
			item.onclick = config_items[i].callback;

		ring.appendChild(item);
	}

	// 创建center对象
	var center = document.createElement("div");
	center.className = className['center'];

	circle.appendChild(ring);
	circle.appendChild(center);

	this.element = circle;

	this._parent.appendChild(circle);

	/**
	 * 注册监听事件
	 */
	circle.addEventListener("click", function(){
		if(circle.className == className["circle"]){
			circle.className = className["open"];
		}else{
			circle.className = className["circle"];
		}
	});
	
	/**
	 * 拖拽事件处理
	 */
	$(circle).drag();
};

/**
 * 隐藏悬浮球
 * @method hide
 * @author JunEnstein 2017-05-23
 */
Note.CircleFloatBox.prototype.hide = function(){
	this.element.style.display = "none";
};

/**
 * 显示悬浮球
 * @method show
 * @author JunEnstein 2017-05-23
 */
Note.CircleFloatBox.prototype.show = function(){
	this.element.style.display = "block";
};